package com.xingchi.framework.common.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * 基本数据传输对象
 *
 * @author xingchi
 * @date 2022/8/18 23:21
 * @modified xingchi
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseDTO<T> {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示消息
     */
    private String message;

    /**
     * 操作状态
     */
    private Boolean success;

    /**
     * 数据载体
     */
    private T data;

    public BaseDTO() {
        this(CommonCode.SUCCESS);
    }

    public BaseDTO(T data) {
        this(CommonCode.SUCCESS, data);
    }

    public BaseDTO(BaseCode baseCode) {
        this.code = baseCode.code();
        this.message = baseCode.message();
        this.success = baseCode.success();
    }

    public BaseDTO(BaseCode baseCode, T data) {
        this.code = baseCode.code();
        this.message = baseCode.message();
        this.success = baseCode.success();
        this.data = data;
    }

}
